<?php
// 本类由系统自动生成，仅供测试用途
class StatisAction extends BaseLoginAction {
   function __construct() {
       parent::__construct();
       
   }
    public function index(){
        $this->redirect("statis");
    }
    
    public function statis(){
        //统计总资产
        
        $sort=D("CapitalSort");
        //累计资产，债务，消费
        $capitals=$sort
                    ->field("sum(number) as allnum,place")
                    ->group("place")
                    ->select();
        
        foreach($capitals as $vo){
            switch ($vo['place']) {
                case "0":
                    $return[]=Array(
                        "id"=>1,
                        "title"=>"资产累计",
                        "number"=>$vo['allnum']
                    );
                    break;
                case "1":
                    $return[]=Array(
                        "id"=>2,
                        "title"=>"债务累计",
                        "number"=>$vo['allnum']
                    );
                    break;
                case "2":
                    $return[]=Array(
                        "id"=>3,
                        "title"=>"消费累计",
                        "number"=>$vo['allnum']
                    );
                    break;
                default:
                    break;
            }
        }
        //统计净资产
        foreach($return as $vo){
            
            if($vo['id']==1){
                $capitals=$vo['number'];
                
            }elseif($vo['id']==2){
                $debt=$vo['number'];
            }
        }
        $return[]=Array(
            "id"=>4,
            "title"=>"净资产",
            "number"=>$capitals-$debt
        );
       
            
       
        $this->assign("rs",$return);
        $this->display();
        
    }
}